package com.qf.test;

import com.qf.mapper.UserMapper;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;
import org.junit.Test;

import java.io.IOException;
import java.io.InputStream;

public class Demo2 {

    @Test
    public void test() throws IOException {
        //1. 加载配置文件,获取字节流
        InputStream inputStream = Resources.getResourceAsStream("mybatis-config.xml");
        //2. 构建工厂
        SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(inputStream);
        //3. 获取SqlSession
        SqlSession sqlSession = factory.openSession();

        //4. 获取到UserMapper接口的代理对象
        UserMapper userMapper = sqlSession.getMapper(UserMapper.class);

        //5. 执行方法
        Long count = userMapper.findCount();
        System.out.println(count);
    }

}
